<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<div class="panel">
    <div id="classes-heading" class="panel-heading bg-gray-light">
        <h3 class="panel-title">指标描述<span id="title-duty-name-targetDesc" class="text-muted"> | </span></h3>

        <ul class="nav nav-tabs" data-ul="targetDesc_nav_ul">
            <li class="active"><a th:href="'#to_targetDesc_tab1'+${targetDesc?.id}" th:id="'targetDesc_tab1'+${targetDesc?.id}" data-toggle="tab">指标描述</a></li>
            <!--<li class=""><a th:href="'#to_targetDesc_tab2'+${targetDesc?.id}" th:id="'targetDesc_tab2'+${targetDesc?.id}" data-toggle="tab">评论明细</a></li>-->
            <li class=""><a th:href="'#to_targetDesc_tab3'+${targetDesc?.id}" th:id="'targetDesc_tab3'+${targetDesc?.id}" data-toggle="tab">驳论明细</a></li>
            <li class=""><a th:href="'#to_targetDesc_tab4'+${targetDesc?.id}" th:id="'targetDesc_tab4'+${targetDesc?.id}" data-toggle="tab">点赞明细</a></li>
            <li class=""><a th:href="'#to_targetDesc_tab5'+${targetDesc?.id}" th:id="'targetDesc_tab5'+${targetDesc?.id}" data-toggle="tab">历史版本</a></li>
        </ul>

    </div>

    <div class="panel-body">
        <div class="tab-content">
            <div class="tab-pane fade in active" th:id="'to_targetDesc_tab1'+${targetDesc?.id}">
                <form th:id="'form_targetDesc_input'+${targetDesc?.id}" class="form-horizontal" autocomplete="off">
                    <input type="hidden" name="keyId" th:value="${targetDesc?.id}">
                    <input type="hidden" name="flowDutyId">
                    <input type="hidden" name="flowDutyName">
                    <input type="hidden" name="parentId" th:value="${target!=null ? target?.id : targetDesc?.target?.id}">

                    <div class="form-group">
                        <label class="col-md-2 control-label">指标定义<i class="fa fa-asterisk txt-color-red"></i></label>
                        <div class="col-md-8">
                            <select id="targetDescDictId" name="targetDescDictId" class="form-control">
                                <option value="">请选择</option>
                                <option th:each="dict : ${targetDescDictList}" th:id="${dict.id}" th:value="${dict.id}" th:text="${dict.name}" th:selected="${dict == targetDesc?.targetDescDict}"></option>
                            </select>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">描述内容</label>
                        <div class="col-md-8">
                            <div th:utext="${targetDesc?.content}"  style="background-color: #eee; padding: 10px"></div>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">描述解释<i class="fa fa-asterisk txt-color-red"></i></label>
                        <div class="col-md-8">
                            <textarea name="explanation" id="explanation" th:text="${targetDesc?.explanation}" rows="4" class="form-control" placeholder="描述解释"></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <label class="col-md-2 control-label">是否存在数据元<i class="fa fa-asterisk txt-color-red"></i></label>
                        <div class="col-md-8">
                            <div class="radio">
                                <input type="radio" name="ifYuan" id="ifYuan0" value="否" class="magic-radio" th:checked="${targetDesc==null || targetDesc?.ifYuan=='否'}" >
                                <label for="ifYuan0">否</label>
                                <input type="radio" name="ifYuan" id="ifYuan1" value="是" class="magic-radio" th:checked="${targetDesc?.ifYuan == '是'}" >
                                <label for="ifYuan1">是</label>
                            </div>
                        </div>
                    </div>

                    <div id="yuanDiv" class="form-group" th:hidden="${targetDesc==null || targetDesc?.ifYuan == '否'}" >
                        <label class="col-md-2 control-label">指标数据元<i class="fa fa-asterisk txt-color-red"></i></label>
                        <div class="col-md-8">
                            <input type="text" name="yuan" id="yuan" th:value="${targetDesc?.yuan}" class="form-control" placeholder="指标数据元">
                        </div>
                    </div>

                </form>
            </div>

            <!--驳论明细-->
            <div class="tab-pane fade in" th:id="'to_targetDesc_tab3'+${targetDesc?.id}">
                <div class="jqGrid_wrapper">
                    <table id="targetDescEvaluate_table"></table>
                    <div id="targetDescEvaluate_page"></div>
                </div>
            </div>

            <!--点赞明细-->
            <div class="tab-pane fade in" th:id="'to_targetDesc_tab4'+${targetDesc?.id}">
                <div class="jqGrid_wrapper">
                    <table id="targetDescZan_table"></table>
                    <div id="targetDescZan_page"></div>
                </div>
            </div>

            <!--历史版本-->
            <div class="tab-pane fade in" th:id="'to_targetDesc_tab5'+${targetDesc?.id}">
                <div class="jqGrid_wrapper">
                    <table id="targetDescHistory_table"></table>
                    <div id="targetDescHistory_page"></div>
                </div>
            </div>
        </div>

    </div>
</div>

<script th:inline="javascript">
    var keyId_targetDesc = [[${targetDesc?.id}]];
    var flowData_targetDesc = {
        keyId : keyId_targetDesc ? keyId_targetDesc : "create",
        formId : "form_targetDesc_input"+[[${targetDesc?.id}]],
        path : "com.hanqian.kepler.core.entity.primary.core.TargetDesc",
        titleId : "title-duty-name-targetDesc"
    };
    var $form_targetDesc = $("#"+flowData_targetDesc.formId);

    $(function(){
        $form_targetDesc.find("input,select,textarea").attr("disabled", true);

        __flow_duty_handle(flowData_targetDesc);
        __flow_button_read_handle(flowData_targetDesc, fn_targetDesc_approve, fn_targetDesc_back, fn_targetDesc_deny, fn_targetDesc_edit, fn_targetDesc_withdraw);

        __select2(flowData_targetDesc.formId + " #targetDescDictId");
    });

    function fn_targetDesc_approve(){
        __confirm_dialog("", "确定通过审批吗？", function(dialogRef){
            __form_save(flowData_targetDesc.formId, "/targetDesc/approve", function(data){
                if(data && data.state === 1){
                    dialogRef.close();
                    __flow_close_layx(flowData_targetDesc);
                }
            })
        });
    }

    function fn_targetDesc_back(){
        __confirm_dialog("", "确定退回吗？", function(dialogRef){
            __form_save(flowData_targetDesc.formId, "/targetDesc/back", function(data){
                if(data && data.state === 1){
                    dialogRef.close();
                    __flow_close_layx(flowData_targetDesc);
                }
            })
        });
    }

    function fn_targetDesc_deny(){
        __confirm_dialog("", "确定否决吗？", function(dialogRef){
            __form_save(flowData_targetDesc.formId, "/targetDesc/deny", function(data){
                if(data && data.state === 1){
                    dialogRef.close();
                    __flow_close_layx(flowData_targetDesc);
                }
            })
        });
    }

    function fn_targetDesc_edit(){
        __flow_close_layx(flowData_targetDesc);
        __layX_html_read(flowData_targetDesc.keyId, "指标描述", "/targetDesc/input?keyId="+flowData_targetDesc.keyId);
    }

    function fn_targetDesc_withdraw(){
        __confirm_dialog("", "确定撤回吗？", function(dialogRef){
            __form_save(flowData_targetDesc.formId, "/targetDesc/withdraw", function(data){
                if(data && data.state === 1){
                    dialogRef.close();
                    __flow_close_layx(flowData_targetDesc);
                }
            })
        });
    }

    //切换标签页要清理流程按钮组
    $("ul[data-ul='targetDesc_nav_ul']").on("click", "li", function(){
        __flow_button_clean_handle(flowData_targetDesc);
    });

    //点击自身 需要重新获取流程按钮组
    $("#targetDesc_tab1"+keyId_targetDesc).on("click", function(){
        __flow_button_read_handle(flowData_targetDesc, fn_targetDesc_approve, fn_targetDesc_back, fn_targetDesc_deny, fn_targetDesc_edit);
    });

    // =========================== 驳论明细 ===========================
    $("#targetDesc_tab3"+keyId_targetDesc).on("click", function(){
        if(!$("#targetDescEvaluate_table").hasClass("ui-jqgrid-btable")){
            __init_jqgrid('targetDescEvaluate_table', 'targetDescEvaluate_page', ctx + 'targetDescEvaluate/list?id='+keyId_targetDesc,
                ["评论人","反对内容","评论时间","操作","id"],
                [
                    {name:'creatorName', index:'creator.name', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name:'content', index:'content', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name:'createTime', index:'createTime', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name: 'act', index: 'act', width: 100, sortable: false, search: false, formatter: actFormat_targetDescEvaluate},
                    {name:'id',index:'id',search:false,hidden:true}
                ]
            );
        }
        setTimeout(function(){
            __jqGrid_width("targetDescEvaluate_table", $("ul[data-ul='targetDesc_nav_ul']").width()-40);
        }, 300);
    });

    function actFormat_targetDescEvaluate(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-default btn-xs" onclick="fn_targetDescEvaluate_delete(\'' + id + '\');">删除</button> ';
        return cellvalue;
    }

    function fn_targetDescEvaluate_delete(id){
        __confirm_dialog("提示", "确认删除此条评论吗", function(){
            __ajax_post(ctx + "targetDescEvaluate/delete/"+id, {}, function(data){
                __toastr(data);
                if(data.state === 1){
                    __reflash_jqgrid("targetDescEvaluate_table");
                }
            })
        })
    }

    // =========================== 历史版本 ===========================
    $("#targetDesc_tab5"+keyId_targetDesc).on("click", function(){
        if(!$("#targetDescHistory_table").hasClass("ui-jqgrid-btable")){
            __init_jqgrid('targetDescHistory_table', 'targetDescHistory_page', ctx + 'targetDesc/list_targetDescHistory?targetDescId='+keyId_targetDesc,
                ["定义描述","点赞数","当前版本","操作","id"],
                [
                    {name:'content', index:'content', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name:'zan', index:'zan', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name:'version', index:'version', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name: 'act', index: 'act', width: 100, sortable: false, search: false, formatter: actFormat_targetDescHistory},
                    {name:'id',index:'id',search:false,hidden:true}
                ]
            );
        }
        setTimeout(function(){
            __jqGrid_width("targetDescHistory_table", $("ul[data-ul='targetDesc_nav_ul']").width()-40);
        }, 300);
    });

    function actFormat_targetDescHistory(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-default btn-xs" onclick="fn_targetDescHistory_read(\'' + id + '\');">查看</button> ';
        return cellvalue;
    }

    function fn_targetDescHistory_read(id){
        __layX_html_read(id, "指标描述 - 历史版本", ctx + "targetDesc/read_targetDescHistory?keyId="+id, {width : "70%", height : "70%"});
    }


    // =========================== 点赞明细 ===========================
    $("#targetDesc_tab4"+keyId_targetDesc).on("click", function(){
        if(!$("#targetDescZan_table").hasClass("ui-jqgrid-btable")){
            __init_jqgrid('targetDescZan_table', 'targetDescZan_page', ctx + 'targetDescZan/list?id='+keyId_targetDesc,
                ["点赞人","点赞日期","操作","id"],
                [
                    {name:'creator.name', index:'creator.name', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name:'createTime', index:'createTime', width:100, search:true, sortable:false, searchoptions: {sopt: ['cn']}},
                    {name: 'act', index: 'act', width: 100, sortable: false, search: false, formatter: actFormat_targetDescZan},
                    {name:'id',index:'id',search:false,hidden:true}
                ]
            );
        }
        setTimeout(function(){
            __jqGrid_width("targetDescZan_table", $("ul[data-ul='targetDesc_nav_ul']").width()-40);
        }, 300);
    });

    function actFormat_targetDescZan(cellvalue, options, rowObject){
        var id = rowObject.id;
        cellvalue = '<button class="btn btn-default btn-xs" onclick="fn_targetDescZan_delete(\'' + id + '\');">删除</button> ';
        return cellvalue;
    }

    function fn_targetDescZan_delete(id){
        __confirm_dialog("提示", "确认删除此条点赞信息吗", function(){
            __ajax_post(ctx + "targetDescZan/delete/"+id, {}, function(data){
                __toastr(data);
                if(data.state === 1){
                    __reflash_jqgrid("targetDescZan_table");
                }
            })
        })
    }

</script>

</html>